<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		p{
			width: 200px;
			height: 200px;
			background: red;
		}
	</style>
	<script>
		
		window.onload= function () {

			box = document.getElementById('box');
			btn = document.getElementById('btn');

			num =200;
			turn =true;
			function run() {

				box.style.width = num+"px";
				box.style.height = num+"px";

				if(num>=400){
					turn = false;
				}

				if(num<=200){
					turn = true;
				}

				if(turn){
					num+=5;
				}else{
					num-=5;
				}
			}

			btn.onclick= function () {

				if(btn.value=="开始"){
					btn.value = "停止";
					time = setInterval(run,20);
				}else{
					btn.value = "开始";
					clearInterval(time);
				}
			}

			
		}

	</script>
</head>
<body>
	<input type="button" value="开始" id="btn">
	<p id="box"></p>
</body>
</html>